package com.ruoyi.web.controller.product;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EaProductProcurement;
import com.ruoyi.system.service.IEaProductProcurementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 集采品种目录Controller
 * 
 * @author ruoyi
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/system/procurement")
public class EaProductProcurementController extends BaseController
{
    @Autowired
    private IEaProductProcurementService eaProductProcurementService;

    /**
     * 查询集采品种目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:procurement:list')")
    @GetMapping("/list")
    public TableDataInfo list(EaProductProcurement eaProductProcurement)
    {
        startPage();
        List<EaProductProcurement> list = eaProductProcurementService.selectEaProductProcurementList(eaProductProcurement);
        return getDataTable(list);
    }

    /**
     * 导出集采品种目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:procurement:export')")
    @Log(title = "集采品种目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EaProductProcurement eaProductProcurement)
    {
        List<EaProductProcurement> list = eaProductProcurementService.selectEaProductProcurementList(eaProductProcurement);
        ExcelUtil<EaProductProcurement> util = new ExcelUtil<EaProductProcurement>(EaProductProcurement.class);
        util.exportExcel(response, list, "集采品种目录数据");
    }

    /**
     * 获取集采品种目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:procurement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(eaProductProcurementService.selectEaProductProcurementById(id));
    }

    /**
     * 新增集采品种目录
     */
    @PreAuthorize("@ss.hasPermi('system:procurement:add')")
    @Log(title = "集采品种目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EaProductProcurement eaProductProcurement)
    {
        return toAjax(eaProductProcurementService.insertEaProductProcurement(eaProductProcurement));
    }

    /**
     * 修改集采品种目录
     */
    @PreAuthorize("@ss.hasPermi('system:procurement:edit')")
    @Log(title = "集采品种目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EaProductProcurement eaProductProcurement)
    {
        return toAjax(eaProductProcurementService.updateEaProductProcurement(eaProductProcurement));
    }

    /**
     * 删除集采品种目录
     */
    @PreAuthorize("@ss.hasPermi('system:procurement:remove')")
    @Log(title = "集采品种目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(eaProductProcurementService.deleteEaProductProcurementByIds(ids));
    }
}
